package com.koi.clubservice;

import com.koi.clubservice.domain.po.Users;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@SpringBootTest
public class MongoDBtest {

    @Autowired
    private MongoTemplate mongoTemplate;


    /**
     * 多条件查询
     */
    @Test
    public void find() {
        //设置查询条件 age小于30,且person_name="张三"
        Criteria criteria = Criteria
                .where("sex").is("女");

        //设置查询条件
        Query query = new Query(criteria);
        //查询
        List<Users> list = mongoTemplate.find(query, Users.class);

        for (Users person : list) {
            System.out.println(person.getHobbies().get(0));
        }
    }



}
